require(['grid', 'topBar', 'layout', 'date'], function () {

    var postData;

    $('#top').topBar({
        left: [{
            type: 'filter-more',
            dateType:'custom',
            search: function () {
                if (getPostData()) {
                    $('#grid').grid('setGridParam', {
                        page:1,
                        datatype: "json",
                        postData: postData
                    }).trigger("reloadGrid");
                }
            },
            item: [{
                text: '时间快捷',
                name1: 'beginTime',
                name2: 'endTime',
                type: 'dateLine'
            }
            ]
        }
        ],
        right: [{
            text: '导出',
            type: 'export-btn',
            item: [{
                text: 'Excel导出',
                click: function () {
                    exportFile('Excel');
                }
            },
                {
                    text: 'PDF导出',
                    click: function () {
                        exportFile('Pdf');
                    }
                }
            ]
        }
        ]
    });

    $('body').layout();

    function exportFile(suffix) {
        if (getPostData()) {
            if ($('#grid').getGridParam("reccount") > 0) {
                var url = "/chargingCount/exportChargingCount" + suffix + ".htm";
                $.exportFile(url, postData);
            }
            else {
                $.messager.alert("提示", "请先查询数据！", "info");
            }
        }
    }

    //获取左侧选择的节点信息
    function getPostData() {
        var rcx = commonFun.getTreeCheckNodeToArgs();
        if (rcx) {
            postData = $.extend(rcx, $("#top").parent().getValues());
        }
        return rcx;
    }

    $('#grid').grid({
        url: "/chargingCount/searchChargingCount.htm",
        multiselect: false,
        colModel: [
            {name: "organName", label: "所属机构", width: "120"},
            {name: "licPltNo", label: "车牌号", width: "120"},
            {name: "lineName", label: "运营线路", width: "120"},
            {name: "carType", label: "车辆型号", width: "120"},
            {name: "bteryMaterialType", label: "电池材料类型", width: "120"},
            {
                name: "chargeCount",
                label: "充电次数",
                align: "right",
                width: "120",
                summaryType: "sum",
                summaryTpl: "小计: {0}"
            },
            {
                name: "chargeInCount",
                label: "过冲次数",
                align: "right",
                width: "120",
                summaryType: "sum",
                summaryTpl: "小计: {0}"
            },
            {
                name: "chargeOutCount",
                label: "过放次数",
                align: "right",
                width: "120",
                summaryType: "sum",
                summaryTpl: "小计: {0}"
            }],
        sortname: "organName",
        showPager: false,
        grouping: true,
        groupingView: {
            groupField: ["organName"],
            groupSummary: [true],
            groupText: ["{0}"],
            groupCollapse: true,//是否收缩行
            showSummaryOnHide: true,//收缩隐藏时是否统计行
            groupOrder: ["asc"],//分组排序方式
            groupColumnShow: [true],//是否显示分组的列
            groupSummaryPos: ["footer"]
        }
    });

});
